package class61To70;

import java.io.*;
import java.util.Arrays;

// 测试链接：https://www.luogu.com.cn/problem/P3366

public class Kruskal {
    public static final int MAX_N = 5001;

    public static final int MAX_M = 200001;

    public static int n, m, u, v, w;

    public static int[] farther = new int[MAX_N];

    public static int[][] edges = new int[MAX_M][3];

    public static void build(int n) {
        for (int i = 0; i <= n; i++) {
            farther[i] = i;
        }
    }

    public static int find(int x) {
        if (x != farther[x]) {
            farther[x] = find(farther[x]);
        }
        return farther[x];
    }

    public static boolean isSameSet(int x, int y) {
        return find(x) == find(y);
    }

    public static void union(int x, int y) {
        int fx = find(x);
        int fy = find(y);
        if (fx != fy) {
            farther[fx] = fy;
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        while (in.nextToken() != StreamTokenizer.TT_EOF) {
            n = (int) in.nval;
            in.nextToken();
            m = (int) in.nval;
            build(n);
            for (int i = 0; i < m; i++) {
                in.nextToken();
                u = (int) in.nval;
                in.nextToken();
                v = (int) in.nval;
                in.nextToken();
                w = (int) in.nval;
                edges[i][0] = u;
                edges[i][1] = v;
                edges[i][2] = w;
            }
            Arrays.sort(edges, 0, m, (a, b) -> a[2] - b[2]);
            int ans = 0;
            int edgeCount = 0;
            for (int i = 0; i < m; i++) {
                if (!isSameSet(edges[i][0], edges[i][1])) {
                    union(edges[i][0], edges[i][1]);
                    ans += edges[i][2];
                    edgeCount++;
                }
            }
            out.println(edgeCount == n - 1 ? ans : "orz");
        }
        out.flush();
        out.close();
        br.close();
    }
}
